package com.hnevc.kaoshi;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.hnevc.kaoshi.adapter.MyAdapter;

public class ThreeActivity extends AppCompatActivity {

    private ListView listView;
    private String[] timu;
    private String[] content;
    private String[] price;
    private int[] imgArray;
    private int[] img2;
    private int[] img3;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.three_activity_layout);
        initView();
        initData();
        initEvent();
    }

    private void initView() {
        listView = findViewById(R.id.listview);
    }

    private void initData() {
        timu = new String[]{"烤鸭","回锅肉","茄子","宫保鸡丁"};
        content = new String[]{"烤鸭烤鸭烤鸭烤鸭烤鸭烤鸭烤鸭烤鸭烤鸭","回锅肉回锅肉回锅肉回锅肉回锅肉回锅肉回锅肉","茄子茄子茄子茄子茄子茄子茄子茄子茄子","宫保鸡丁宫保鸡丁宫保鸡丁宫保鸡丁宫保鸡丁宫保鸡丁"};
        price = new String[]{"88.0元/份","12.3元/份","1.0元/份","0.2元/份"};
        imgArray = new int[]{R.drawable.one,R.drawable.two,R.drawable.three,R.drawable.four};
        img2 = new int[]{R.drawable.add,R.drawable.add,R.drawable.add,R.drawable.add};
        img3 = new int[]{R.drawable.sub,R.drawable.sub,R.drawable.sub,R.drawable.sub};

        listView.setAdapter(new MyAdapter(ThreeActivity.this,timu,content,price, imgArray, img2, img3));
    }

    private void initEvent() {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(ThreeActivity.this,DetailActivity.class);
                intent.putExtra("name",timu[position]);
                intent.putExtra("content",content[position]);
                intent.putExtra("price",price[position]);
                intent.putExtra("img1",imgArray[position]);
                intent.putExtra("img2",img2[position]);
                intent.putExtra("img3",img3[position]);
                startActivity(intent);
            }
        });
    }
}
